package com.zm.demo.core.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import static java.lang.System.out;

/**
 * @author zoum
 * @create 2020/1/7 14:13
 */
public class PreorderTree {

    public List<Integer> preorder(Node root) {
        List<Integer> result = new ArrayList<>();
        if (root != null){
            result.add(root.val);
            getLevelMap(result, root.children);
        }
        return result;

    }

    public void getLevelMap(List<Integer> list, List<Node> children){
        if (children == null || children.size() == 0){
            return;
        }
        for (int i = 0; i < children.size(); i++) {
            Node _this = children.get(i);
            list.add(_this.val);
            getLevelMap(list, _this.children);
        }
    }



    public static void main(String[]args){
        List<Node> list3 = Arrays.asList(new Node(5, null), new Node(6, null));

        List<Node> list2 = Arrays.asList(new Node(3, list3), new Node(2, null), new Node(4, null));

        Node root = new Node(1, list2);


//        {"val":1,"children":[{"val":3, "children":[{"val":5, "children":null},{"val":5, "children":null}]},{"val":2, "children":null},{"val":4, "children":null}]}
        out.println(new PreorderTree().preorder(root));
    }

}

